#include "utils.h"
#include "sdf.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(){

    void ** pdh;
	pdh = (void **) malloc(20);
	int ret;

    ret = SDF_OpenDevice(pdh);
	if(ret != SDR_OK){
        printf("error!");
	} else {
		printf("device opened!\n");
	}

    DEVICEINFO testdi;
    ret = SDF_GetDeviceInfo(pdh, &testdi);
	if(ret != SDR_OK){
        printf("error!");
	} else {
        printf("Issuer Name: %s\n", testdi.IssuerName);
        printf("Device Name: %s\n", testdi.DeviceName);
        printf("Device Serial: %s\n", testdi.DeviceSerial);
        printf("Device Version: %d\n", testdi.DeviceVersion);
		
	}

    char pRandom[80]={0};

    ret = SDF_GenerateRandom(*pdh,1, pRandom);
	if(ret != SDR_OK){
        printf("error!");
	} else {
        //for(int i=0; pRandom[i]; i++)
            puts(pRandom);
	}
	memset(pRandom,0,80);
	ret = SDF_GenerateRandom(*pdh,5, pRandom);
	if(ret != SDR_OK){
        printf("error!");
	} else {
        // for(int i=0; pRandom[i]; i++)
        //     printf("%d\n", pRandom[i]);
		puts(pRandom);
	}

	memset(pRandom,0,80);
	ret = SDF_GenerateRandom(*pdh,10, pRandom);
	if(ret != SDR_OK){
        printf("error!");
	} else {
        // for(int i=0; pRandom[i]; i++)
        //     printf("%d\n", pRandom[i]);
		puts(pRandom);
	}

	memset(pRandom,0,80);
	ret = SDF_GenerateRandom(*pdh,20, pRandom);
	if(ret != SDR_OK){
        printf("error!");
	} else {
        // for(int i=0; pRandom[i]; i++)
        //     printf("%d\n", pRandom[i]);
		puts(pRandom);
	}


    // ret = SDF_CloseDevice(*pdh);
	
	// if(ret != SDR_OK){
    //     printf("error!");
	// } else {
	// 	free(pdh);
	// 	printf("device closed!\n");
	// // }
	// unsigned char bs1 [] = "1010010100011100";
	// char * ba1=(char *)malloc((strlen(bs1)+7)/8+1);
	// Bitstr2ByteArr(bs1, ba1);
	// for (unsigned char * opt = ba1; *opt!='\0'; opt++)
	// {
	// 	printf("%02x ",*opt);
	// }
	// putchar('\n');
	// char ba2[] = {0x12, 0x19,0};
	// char * bs2=(char *)malloc(strlen(ba2)*8+1);
	// ByteArr2Bitstr(ba2,bs2);
	// puts(bs2);
	// return 0;

}
